var express = require('express');
var resp = require('../config/responseJson');
var Post = require('../model/post');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
    let option = {
        user: req.session.user, //根据user是否存在于session中，显示navForm
        isIndexRouter: true,
        resp: resp.noting,
        isActivePostLi: ''
    };
    Post.find({})
        .sort({ ctime: 'desc' })
        .then(data => {
            option.posts = data;
            option.rowNum = Math.ceil(data.length / 3);
            res.render('layoutPage', option);
        })
        .catch(err => {
            next(err);
        });
});

module.exports = router;
